package com.hadwinling.alogriithm.core.wordcount

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Spark02_WordCount {
  def main(args: Array[String]): Unit = {

    // TODO
    val conf = new SparkConf().setMaster("local[*]").setAppName("spark02_wordcount")
    val sc = new SparkContext(config = conf)

    //ToDO
    val lines:RDD[String] = sc.textFile("datas")


    val words:RDD[String] = lines.flatMap(_.split(" "))

    var wordToone = words.map(words=>(words,1))

    var wordToSum :RDD[(String,Int)] = wordToone.reduceByKey(_+_)

    val array:Array[(String,Int)] = wordToSum.collect()
    array.foreach(println)

    sc.stop()








  }

}
